package com.netflexitysolutions.amazonws.ec2.internal.operations;

import java.util.List;
import java.util.Set;

import com.amazonaws.ec2.doc._2009_04_04.DescribeReservedInstancesResponseType;
import com.amazonaws.ec2.doc._2009_04_04.DescribeReservedInstancesSetItemType;
import com.amazonaws.ec2.doc._2009_04_04.DescribeReservedInstancesSetType;
import com.amazonaws.ec2.doc._2009_04_04.DescribeReservedInstancesType;
import com.netflexitysolutions.amazonws.ec2.EC2;
import com.netflexitysolutions.amazonws.ec2.ReservedInstances;
import com.netflexitysolutions.amazonws.ec2.internal.ModelUtil;

public class DescribeReservedInstancesOperation 
				extends ObjectSetOperationExecutor<DescribeReservedInstancesType, List<ReservedInstances>> {

	public DescribeReservedInstancesOperation(EC2 ec2, Set<String> objectIds) {
		super(ec2, objectIds);
	}

	@Override
	protected List<ReservedInstances> call(DescribeReservedInstancesType request) {
		if (objectIds != null) {
			DescribeReservedInstancesSetType set = new DescribeReservedInstancesSetType();
			List<DescribeReservedInstancesSetItemType> list = set.getItem();
			for (String instanceId : objectIds) {
				DescribeReservedInstancesSetItemType item = new DescribeReservedInstancesSetItemType();
				item.setReservedInstancesId(instanceId);
				list.add(item);
			}
			request.setReservedInstancesSet(set);
		}
		DescribeReservedInstancesResponseType response = getEC2().getService().describeReservedInstances(request);
		return ModelUtil.toDomainType(response.getReservedInstancesSet());
	}

}
